#include "PlatoonIdleState.h"

PlatoonIdleState::PlatoonIdleState(Context* context) : State(context)//, mFramesIdle(0)
{
	BWAPI::TilePosition initPos = BWAPI::Broodwar->self()->getStartLocation();
	
	mFacingAngle = (initPos.x() < 30)? 1 : -1;
	mStep = IDLE_STEP;
}

PlatoonIdleState::~PlatoonIdleState(void)
{
}

void PlatoonIdleState::handle()
{
	Platoon* platoon = static_cast<Platoon*>(mContext);
	
	// If enemy has been seen
	if (EnemyManager::self() && EnemyManager::self()->hasVisibleUnits())
	{
		platoon->changeState(new PlatoonAttackState(mContext));
	}

	else if(platoon->hasSpaceForFormation(Formation::LineFormation))
	{
		platoon->goLineFormation(0);
		platoon->changeState(new PlatoonScoutState(mContext));
	}

	else if(!platoon->isUnitMoving())
	{
		BWAPI::Position newPosition(mFacingAngle*mStep, 0); //FIXME hard-coded position
		platoon->move(newPosition, true);
	}
}